#include "VBO.h"
#include<glad/glad.h>
#include<GLFW/glfw3.h>

namespace OCPP
{
	VBO::VBO(Vector3List& vertices)
	{
		glGenBuffers(1, &ID);
		glBindBuffer(GL_ARRAY_BUFFER, ID);
		glBufferData(GL_ARRAY_BUFFER, vertices.size() * sizeof(Vector3), vertices.data(), GL_STATIC_DRAW);
	}

	VBO::VBO(Matrix4List& instances)
	{
		Matrix4List list;
		for (const auto& m : instances)
		{
			list.push_back(m.transpose());
		}
		glGenBuffers(1, &ID);
		glBindBuffer(GL_ARRAY_BUFFER, ID);
		glBufferData(GL_ARRAY_BUFFER, instances.size() * sizeof(Matrix4), list.data(), GL_STATIC_DRAW);

	}

	VBO::VBO(VertexList& vertices)
	{
		glGenBuffers(1, &ID);
		glBindBuffer(GL_ARRAY_BUFFER, ID);
		glBufferData(GL_ARRAY_BUFFER, vertices.size() * sizeof(Vertex), vertices.data(), GL_STATIC_DRAW);
	}

	VBO::VBO(VertexListPCT& vertices)
	{
		glGenBuffers(1, &ID);
		glBindBuffer(GL_ARRAY_BUFFER, ID);
		glBufferData(GL_ARRAY_BUFFER, vertices.size() * sizeof(VertexPCT), vertices.data(), GL_STATIC_DRAW);
	}

	VBO::~VBO()
	{
		glDeleteBuffers(1, &ID);
	}

	void VBO::bind()
	{
		glBindBuffer(GL_ARRAY_BUFFER, ID);
	}

	void VBO::unbind()
	{
		glBindBuffer(GL_ARRAY_BUFFER, 0);
	}
}